package com.soft.javase.day08.login;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/27
 */
public class UserTest {
    public static void main(String[] args) {
        List<User> users = new ArrayList<>();
        users.add(new User("张三","111"));
        users.add(new User("李四","222"));
        users.add(new User("王五","333"));
        login(users);

    }
    public static boolean login(List<User> users) {
        Scanner sc = new Scanner(System.in);
        boolean flag = false;
        A:for(int i=0;i<3;i++){
            System.out.println("请输入用户名：");
            String username = sc.nextLine();
            System.out.println("请输入密码：");
            String pwd = sc.nextLine();
            B:for (User user : users) {
                if(username.equals(user.getName())&&pwd.equals(user.getPassword())){
                    flag = true;
                    System.out.println("登录成功");
                    break A;
                }
            }

        }
        if(!flag){
            System.out.println("三次机会已用完，登录失败");
        }
        return flag;
    }
}
